package com.coolcard.framework.base;

import com.coolcard.system.enums.common.SecretLevel;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import lombok.Getter;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.time.LocalDateTime;

/**
 * 基础实体类
 * - 实现 ID、创建时间、更新时间、删除标记、乐观锁等基础字段
 */
@Getter
@MappedSuperclass  // 用于标识实体类父类
@EntityListeners(AuditingEntityListener.class)  // 实体监听器，用于自动填充创建时间和更新时间
public abstract class BaseEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column
    private SecretLevel secretLevel = SecretLevel.PUBLIC;  // 密级

    @CreatedDate
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTime;  // 创建时间

    @LastModifiedDate
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime updateTime;  // 更新时间

    @Column
    @JsonIgnore
    private Boolean isDeleted = false;  // 删除标记

    @Version
    @JsonIgnore
    private Long version;  // 乐观锁

}
